#include "messagesendingarea.h"

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QScrollBar>

MessageSendingArea::MessageSendingArea(QWidget *parent)
    : QWidget{parent}
{
    // 1. 设置必要属性
    this->setFixedHeight(145);
    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    this->setStyleSheet("QWidget { background-color: rgb(245, 245, 245); border-top: 1px solid rgb(236, 236, 236); }");


    // 2. 设置纵置布局
    QVBoxLayout* vlayout = new QVBoxLayout();
    vlayout->setContentsMargins(12, 10, 12, 13);
    vlayout->setSpacing(0);
    this->setLayout(vlayout);

    // 3. 添加四个按钮
    // 3.1 设置水平布局
    QHBoxLayout* btn_layout = new QHBoxLayout();
    btn_layout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    btn_layout->setContentsMargins(8, 0, 0, 0);
    btn_layout->setSpacing(11);
    vlayout->addLayout(btn_layout);


    QSize same_size(23, 23);
    QString same_style = "QPushButton { border-radius: 5px; border: none; background-color: transparent; }";
    same_style += "QPushButton::pressed { background-color: rgb(209, 209, 209); }";

    // 3.2 添加 "发送图片" 按钮
    send_image_btn = new QPushButton();
    send_image_btn->setStyleSheet(same_style);
    send_image_btn->setFixedSize(same_size);
    send_image_btn->setIconSize(same_size);
    send_image_btn->setIcon(QIcon(":/resource/image/image.png"));
    btn_layout->addWidget(send_image_btn);

    // 3.3 添加 "发送文件" 按钮
    send_file_btn = new QPushButton();
    send_file_btn->setStyleSheet(same_style);
    send_file_btn->setFixedSize(same_size);
    send_file_btn->setIconSize(same_size);
    send_file_btn->setIcon(QIcon(":/resource/image/file.png"));
    btn_layout->addWidget(send_file_btn);

    // 3.4 添加 "发送语音" 按钮
    send_speech_btn = new QPushButton();
    send_speech_btn->setStyleSheet(same_style);
    send_speech_btn->setFixedSize(same_size);
    send_speech_btn->setIconSize(same_size);
    send_speech_btn->setIcon(QIcon(":/resource/image/speech_sound.png"));
    btn_layout->addWidget(send_speech_btn);

    // 3.5 添加 "历史消息" 按钮
    history_msg_btn = new QPushButton();
    history_msg_btn->setStyleSheet(same_style);
    history_msg_btn->setFixedSize(same_size);
    history_msg_btn->setIconSize(same_size);
    history_msg_btn->setIcon(QIcon(":/resource/image/history_msg.png"));
    btn_layout->addWidget(history_msg_btn);

    // 4. 添加消息编辑区
    input_field = new QPlainTextEdit();
    input_field->setFixedHeight(118);
    input_field->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

    QString input_field_style = "QPlainTextEdit { background-color: transparent; border: none; }";
    input_field_style += "QPlainTextEdit { color: rgb(56, 0, 0); font-size: 14px; padding: 10px; }";

    input_field_style += "QPlainTextEdit { selection-color: rgb(0, 0, 0); selection-background-color: rgb(155, 202, 239); }";

    // padding 设置内边距，可用范围和边框之间的距离
    input_field->setStyleSheet(input_field_style);

    input_field->verticalScrollBar()->setStyleSheet("QScrollBar {background-color: rgb(210, 210, 210); width: 2px; }");
    input_field->horizontalScrollBar()->setStyleSheet("QScrollBar { width: 2px; }");

    vlayout->addWidget(input_field);

    // 5. 添加消息发送按钮
    send_msg_btn = new QPushButton();
    send_msg_btn->setFixedSize(QSize(101, 32));
    QString send_msg__btn_style = "QPushButton { background-color: rgb(233, 233, 233); border: none; border-radius: 5px; }";
    send_msg__btn_style += "QPushButton { color: rgb(6, 174, 86); font-size: 14px; }";
    send_msg__btn_style += "QPushButton::pressed { background-color: rgb(198, 198, 198); }";
    send_msg_btn->setStyleSheet(send_msg__btn_style);
    send_msg_btn->setText("发送");

    vlayout->addWidget(send_msg_btn, 0, Qt::AlignBottom | Qt::AlignRight);

    // 6. 初始化信号槽
}


void MessageSendingArea::InitSignalSlot()
{

}
